from django.contrib import admin

# Register your models here.

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User

"""
超级管理员可以看到所有人的所有字段
其它成员自己看到自己的字段
"""


# 自定义UserAdmin类
class CustomUserAdmin(UserAdmin):
    # 在这里添加你要在admin界面展示和编辑的字段
    fieldsets = (
        (None, {'fields': ('username', 'password')}),
        ('个人信息', {'fields': ('name', 'title', 'avatar', 'phone_num', 'contact_address', 'is_cp', 'is_good_teacher',
                                 'other_title')}),
        ('权限', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}),
        ('重要日期', {'fields': ('last_login', 'date_joined')}),
    )

    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('username', 'password1', 'password2', 'name', 'title', 'avatar',
                       'phone_num', 'contact_address', 'is_cp', 'is_good_teacher',
                       'other_title'),
        }),
    )
    list_display = ('username', 'name', 'title', 'email', 'is_staff')

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(id=request.user.id)


admin.site.register(User, CustomUserAdmin)
